package com.srit.map.web.action;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.srit.core.constant.SystemConstant;
import com.srit.core.struts2.action.CrudAction;
import com.srit.map.business.bean.Menu;
import com.srit.map.business.bean.User;
import com.srit.map.business.service.UserService;

/**
 * 登陆模块
 * 
 * @author guan
 * 
 */
public class LoginAction extends CrudAction {
	private User user = new User();
	@Autowired(required = true)
	private UserService userService;

	public void validateLogin() {
		User tmp = userService.getUserByUsername(user);
		if (tmp == null) {
			addActionError(user.getUsername() + "不存在!");
		} else {
			if (!user.getPassword().equals(tmp.getPassword())) {
				addActionError(user.getUsername() + "密码错误!");
			}
		}
	}

	public String login() {
		session.put(SystemConstant.SESSION_USER, user);
		
		return SUCCESS;
	}

	public String logout() {
		session.remove(SystemConstant.SESSION_USER);
		return LOGIN;
	}

	@Override
	public Object getModel() {
		return user;
	}

}
